package com.stanwind.sgit.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * StringUtils
 *
 * @author : Stan
 * @version : 1.0
 * @date :  2019-11-29 10:43
 **/
public class StringUtils {

    public static boolean isBlank(String val) {
        return val == null || val.length() == 0;
    }

    public static boolean isNotBlank(String val) {
        return !isBlank(val);
    }

    public static String readFromInputStream(InputStream in, String charset) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len = -1;
        while ((len = in.read(buffer)) != -1) {
            baos.write(buffer, 0, len);
        }
        baos.close();
        in.close();

        return baos.toString(charset);
    }

    public static String readFromInputStream(InputStream in) throws IOException {
        return readFromInputStream(in, ShellUtil.SHELL_CHARSET);
    }
}
